#include <iostream>

#include "gtest/gtest.h"
#include "ClientApi.h"
#include <memory>
#include "Log.h"
#include <vector>
#include <boost/filesystem.hpp>

static boost::shared_ptr<CSApi::ClientApi> api;

#define STORAGE_NAME "Storage"

class File : public ::testing::Test {
	protected:

		static void SetUpTestCase()	{
			FUNCTION_TRACK
			ASSERT_NO_THROW({
				api = CSApi::CreateClientApi("127.0.0.1", "5001", "root", "root");
				boost::filesystem::create_directories("/tmp/File");
                boost::filesystem::create_directories("/tmp/File/Folder");
			});
            ASSERT_TRUE(api.get() != NULL);
            FILE *f = fopen("/tmp/File/found.txt", "w");
            ASSERT_TRUE(f != NULL);
            fprintf(f, "TEST");
            fclose(f);

            f = fopen("/tmp/File/found-deleteme.txt", "w");
            ASSERT_TRUE(f != NULL);
            fprintf(f, "TEST");
            fclose(f);
			ASSERT_NO_THROW({
				ASSERT_TRUE(api->Share("/FileTests", "/tmp/File", STORAGE_NAME));
                ASSERT_TRUE(api->Share("/FileTests-found.txt", "/tmp/File/found.txt", STORAGE_NAME));
			});
		}

		static void TearDownTestCase() {
			ASSERT_NO_THROW({
				api.reset();
                boost::filesystem::remove_all("/tmp/File");
			});
		}
};

TEST_F(File, FileExists_FailedFolderExists) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
        api->FileExists("/FileTests/Folder");
    }, CSApi::CSException_FolderExits);
}

TEST_F(File, FileExists_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
        api->FileExists("/FileTests/File2/Cos");
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileExists_FailedInvalidPath) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
        api->FileExists("/FileTests/");
    }, CSApi::CSException_InvalidPath);
}

TEST_F(File, FileExists_SuccessNotFound) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_NO_THROW({
        ASSERT_FALSE(api->FileExists("/FileTests/notfound.txt"));
    });
}

TEST_F(File, FileExists_SuccessFound) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileExists("/FileTests/found.txt"));
    });
}

TEST_F(File, FileOpen_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
       api->FileOpen("/FileTests/found2.txt", "");
    }, CSApi::CSException_WrongArgument);
    EXPECT_THROW({
       api->FileOpen("", "");
    }, CSApi::CSException_WrongArgument);
    EXPECT_THROW({
       api->FileOpen("/FileTests/asdasd/asdasd/asd/found2.txt", "w");
    }, CSApi::CSException_WrongArgument);
    EXPECT_THROW({
       api->FileOpen("/FileTests/found.txt", "g");
    }, CSApi::CSException_WrongArgument);
    EXPECT_THROW({
       api->FileOpen("/FileTests/found2.txt", " ");
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileOpen_FailedInvalidPath) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
       api->FileOpen("/FileTests/", "w");
    }, CSApi::CSException_InvalidPath);
}

TEST_F(File, FileOpen_FailedFolderExits) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
       api->FileOpen("/FileTests/Folder", "r");
    }, CSApi::CSException_FolderExits);
}

TEST_F(File, FileOpen_FailedFileNotExits) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
       api->FileOpen("/FileTests/plik2.txt", "r");
    }, CSApi::CSException_FileNotExits);
}

TEST_F(File, FileOpen_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    EXPECT_THROW({
       api->FileOpen("/plik2.txt", "w");
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileOpen_SuccessCreate) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;
    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/FileOpen_SuccessCreate.txt", "w");
    });
    ASSERT_TRUE(f!=0);
    EXPECT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/FileOpen_SuccessCreate.txt"));
    });
    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileOpen_SuccessRead) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileOpen_SuccessAppend) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "a+");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileOpen_SuccessDoubleOpen) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0, f2 = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
       f2 = api->FileOpen("/FileTests/found.txt", "r");
    });

    EXPECT_TRUE(f2!=0);
    EXPECT_NE(f, f2);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f2));
    });
}

TEST_F(File, FileClose_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileClose(0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileClose_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileClose(3423543);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileClose(12308);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileClose_FailedInvalidOperationDoubleClose) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });

    EXPECT_THROW({
       api->FileClose(f);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileClose_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileSize_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileSize(0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileSize_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileSize(3423543);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileSize(12308);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileSize_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint64_t ret = 0xFFFFFFFF;
    EXPECT_NO_THROW({
        ret = api->FileSize(f);
    });

    EXPECT_EQ(ret, boost::filesystem::file_size("/tmp/File/found.txt"));

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileTimestamp_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileTimestamp(0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileTimestamp_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileTimestamp(3423543);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileTimestamp(12308);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileTimestamp_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint64_t ret = 0xFFFFFFFF;
    EXPECT_NO_THROW({
        ret = api->FileTimestamp(f);
    });

    EXPECT_EQ(ret, boost::filesystem::last_write_time("/tmp/File/found.txt"));

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileTell_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileTell(0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileTell_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileTell(323543);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileTell(121308);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileTell_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint64_t ret = 0xFFFFFFFF;
    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    ASSERT_TRUE(ret == 0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileSeek_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileSeek(0, 0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileSeek_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileSeek(323543, 0);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileSeek(121308, 0);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileSeek_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint64_t ret = 0xFFFFFFFF;
    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    EXPECT_TRUE(ret == 0);

    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileSeek(f, 1));
    });

    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    EXPECT_EQ(ret, 1);

    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileSeek(f, 2));
    });

    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    EXPECT_EQ(ret, 2);

    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileSeek(f, -1));
    });

    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    EXPECT_EQ(ret, boost::filesystem::file_size("/tmp/File/found.txt"));

    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileSeek(f, -2));
    });

    EXPECT_NO_THROW({
        ret = api->FileTell(f);
    });

    EXPECT_EQ(ret, boost::filesystem::file_size("/tmp/File/found.txt")-1);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileEof_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileEof(0);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileEof_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileEof(323543);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileTell(121308);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileEof_Success) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
        EXPECT_FALSE(api->FileEof(f));
    });

    uint32_t tmp = boost::filesystem::file_size("/tmp/File/found.txt")+1;
    uint8_t *ptr = new uint8_t[tmp];
    EXPECT_NO_THROW({
        EXPECT_EQ(api->FileRead(f, tmp, ptr), tmp-1);
    });
    delete []ptr;
    EXPECT_NO_THROW({
        EXPECT_TRUE(api->FileEof(f));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileRead_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileRead(0, 0, NULL);
    }, CSApi::CSException_WrongArgument);

    EXPECT_THROW({
        api->FileRead(0, 1, NULL);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileRead_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    uint8_t tmp;
    EXPECT_THROW({
        api->FileRead(323543, 1, &tmp);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileRead(121308, 1, &tmp);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileRead_SuccessZeroRead) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint8_t ptr[100];

    EXPECT_NO_THROW({
        EXPECT_EQ(0, api->FileRead(f, 0, ptr));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileRead_SuccessAllRead) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint8_t ptr[100];

    EXPECT_NO_THROW({
        EXPECT_EQ(boost::filesystem::file_size("/tmp/File/found.txt"), api->FileRead(f, 100, ptr));
    });

    ptr[4] = 0;
    EXPECT_EQ(strcmp("TEST", (const char*)ptr),0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileRead_SuccessByByteRead) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    ASSERT_NO_THROW({
       EXPECT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found.txt"));
    });

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint8_t ptr[2];

    EXPECT_NO_THROW({
        EXPECT_EQ(1, api->FileRead(f, 1, ptr));
    });

    EXPECT_EQ(ptr[0], 'T');

    EXPECT_NO_THROW({
        EXPECT_EQ(1, api->FileRead(f, 1, ptr));
    });

    EXPECT_EQ(ptr[0], 'E');

    EXPECT_NO_THROW({
        EXPECT_EQ(1, api->FileRead(f, 1, ptr));
    });

    EXPECT_EQ(ptr[0], 'S');

    EXPECT_NO_THROW({
        EXPECT_EQ(1, api->FileRead(f, 2, ptr));
    });

    EXPECT_EQ(ptr[0], 'T');

    EXPECT_NO_THROW({
        EXPECT_TRUE(api->FileEof(f));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileWrite_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileWrite(0, 0, NULL);
    }, CSApi::CSException_WrongArgument);

    EXPECT_THROW({
        api->FileWrite(0, 1, NULL);
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileWrite_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    uint8_t tmp;
    EXPECT_THROW({
        api->FileWrite(323543, 1, &tmp);
    }, CSApi::CSException_InvalidOperation);

    EXPECT_THROW({
        api->FileWrite(121308, 1, &tmp);
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileWrite_FailedWrongMode) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found.txt", "r");
    });

    ASSERT_TRUE(f!=0);

    uint8_t ptr[100];

    EXPECT_NO_THROW({
        EXPECT_EQ(0, api->FileWrite(f, 4, (const uint8_t*)"DUPA"));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileWrite_SuccessZeroWrite) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found_new.txt", "w");
    });

    ASSERT_TRUE(f!=0);

    uint8_t ptr[100];

    EXPECT_NO_THROW({
        EXPECT_EQ(0, api->FileWrite(f, 0, ptr));
    });

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileWrite_SuccessTextWrite) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);
    THANDLE f = 0;

    EXPECT_NO_THROW({
       f = api->FileOpen("/FileTests/found_new.txt", "w+");
    });

    ASSERT_TRUE(f!=0);

    EXPECT_NO_THROW({
        EXPECT_EQ(0, api->FileWrite(f, 4, (const uint8_t*)"DUPA"));
    });

    EXPECT_NO_THROW({
        EXPECT_TRUE(api->FileSeek(f, 0));
    });

    uint8_t tmp[5];

    EXPECT_NO_THROW({
        EXPECT_EQ(4, api->FileRead(f, 4, tmp));
    });

    tmp[4] = 0;
    EXPECT_EQ(strcmp("DUPA", (const char*)tmp),0);

    EXPECT_NO_THROW({
       ASSERT_TRUE(api->FileClose(f));
    });
}

TEST_F(File, FileDelete_FailedWrongArgument) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileDelete("fdsdf/sfdsdf/sfsdf");
    }, CSApi::CSException_WrongArgument);

    EXPECT_THROW({
        api->FileDelete("/adas/../../");
    }, CSApi::CSException_WrongArgument);

    EXPECT_THROW({
        api->FileDelete("/adas<");
    }, CSApi::CSException_WrongArgument);
}

TEST_F(File, FileDelete_FailedInvalidPath) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileDelete("fdsdf/");
    }, CSApi::CSException_InvalidPath);

    EXPECT_THROW({
        api->FileDelete("");
    }, CSApi::CSException_InvalidPath);

    EXPECT_THROW({
        api->FileDelete("/");
    }, CSApi::CSException_InvalidPath);

    EXPECT_THROW({
        api->FileDelete("/Folder/");
    }, CSApi::CSException_InvalidPath);
}

TEST_F(File, FileDelete_FailedFolderExits) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileDelete("/FileTests");
    }, CSApi::CSException_FolderExits);

    EXPECT_THROW({
        api->FileDelete("/FileTests/Folder");
    }, CSApi::CSException_FolderExits);
}

TEST_F(File, FileDelete_FailedInvalidOperation) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_THROW({
        api->FileDelete("/FileTests-found.txt");
    }, CSApi::CSException_InvalidOperation);
}

TEST_F(File, FileDelete_SuccessFileNotFound) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    EXPECT_NO_THROW({
        ASSERT_TRUE(api->FileDelete("/FileTests/found-deleteme2.txt"));
    });
}

TEST_F(File, FileDelete_SuccessFileRemoved) {
    FUNCTION_TRACK
    ASSERT_TRUE(api.get()!=NULL);

    ASSERT_NO_THROW({
       ASSERT_TRUE(boost::filesystem::is_regular_file("/tmp/File/found-deleteme.txt"));
    });

    ASSERT_NO_THROW({
        ASSERT_TRUE(api->FileDelete("/FileTests/found-deleteme.txt"));
    });

    ASSERT_NO_THROW({
       ASSERT_FALSE(boost::filesystem::is_regular_file("/tmp/File/found-deleteme.txt"));
    });
}


